package leetcode.code0665;

import leetcode.IDebug;
import leetcode.helper.HelpDebug;

public class Solution implements IDebug {

	public boolean checkPossibility(int[] nums) {
		int cnt = 0;
		for (int i = 1; i < nums.length; i++) {
			if (nums[i - 1] > nums[i]) {
				cnt++;
				if (i - 2 >= 0 && (nums[i - 2] == nums[i - 1] || nums[i - 2] > nums[i])) {
					nums[i] = nums[i - 1];
				}
			}
		}
		return cnt < 2;
	}

	@Override
	public void debug4() {
		HelpDebug.compare(false, this.checkPossibility(HelpDebug.str2array3("[3,4,2,3]")));
		HelpDebug.compare(true, this.checkPossibility(HelpDebug.str2array3("[-1,4,2,3]")));
		HelpDebug.compare(true, this.checkPossibility(HelpDebug.str2array3("[4,2,3]")));
		HelpDebug.compare(false, this.checkPossibility(HelpDebug.str2array3("[4,2,1]")));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
